package com.wyk.controller;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.Map;

import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;

import org.apache.commons.io.IOUtils;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

import com.google.common.collect.Maps;

@Controller
public class ImageController {
	@RequestMapping("/admin/upload")
	@ResponseBody
	public Map<String, Object>upload(HttpServletRequest request,@RequestParam("file")MultipartFile multipartFile) throws IOException{
		String name = multipartFile.getName();
		System.out.println(name);
		Map<String, Object> map = Maps.newHashMap();
		if(request.getAttribute("error")!=null){
			map.put("msg", request.getAttribute("error").toString());
			map.put("code", 100);
			return map;
		}
		map.put("msg", "成功");
		map.put("code", 200);
		map.put("data", "http://xrj.oss-cn-hangzhou.aliyuncs.com/data/20170307/60811488858567883.jpg");
		System.out.println(map);
		return map;
	}
}
